package b4.view.component.task
{
	import b4.util.BFont;
	import b4.util.GameProfile;
	
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	
	import org.aswing.JFrame;
	import org.aswing.JScrollPane;
	import org.aswing.JTree;
	import org.aswing.tree.DefaultMutableTreeNode;
	import org.aswing.tree.DefaultTreeModel;
	import org.aswing.tree.GeneralTreeCellFactory;

	public class TaskDialog extends JFrame
	{
		public function TaskDialog()
		{
			super();
			
			var root:DefaultMutableTreeNode = new DefaultMutableTreeNode(createItem("JTree"));
			var parent:DefaultMutableTreeNode;
			parent = new DefaultMutableTreeNode(createItem("folder1"));
			root.append(parent);
			var i:int;
			for(i=0; i<10; i++){
				parent.append(new DefaultMutableTreeNode(createItem("<font color='#FF0000'>item one " + i + "</font>")));
			}
			parent = new DefaultMutableTreeNode(createItem("folder2"));
			root.append(parent);
			for(i=0; i<20; i++){
				parent.append(new DefaultMutableTreeNode(createItem("item two " + i)));
			}
				parent = new DefaultMutableTreeNode(createItem("folder3"));
			root.append(parent);
			for(i=0; i<30; i++){
				parent.append(new DefaultMutableTreeNode(createItem("item three " + i)));
			}
			var model:DefaultTreeModel = new DefaultTreeModel(root);
					
			var tree:JTree = new JTree();
			tree.setRootVisible(false);
			tree.setFixedCellWidth(80);
			tree.setRowHeight(18);
			tree.setCellFactory(new GeneralTreeCellFactory(TaskTreeCell));
			tree.setModel(model);
			var scrollPane:JScrollPane = new JScrollPane(tree);
			this.setTitle("任务");
			this.setContentPane(scrollPane);
			this.setComBoundsXYWH(GameProfile.stageWidth - 320, 100, 320, 400);
		}
		
		private function createItem(value:String):*{
			var tipText:TextField = new TextField();
			tipText.selectable = false;
        	tipText.autoSize = TextFieldAutoSize.LEFT;
        	tipText.wordWrap = true;
        	tipText.multiline = true;
        	var texFormat:TextFormat = new TextFormat(BFont.DEFAULT_FONT, 14, 0xFFFFFF);
			tipText.defaultTextFormat = texFormat;
			tipText.htmlText = value;
			tipText.y = height > 0 ? height - 8: 0;
			return value;
		}
		
	}
}